<?php
include_once 'app/until/GFW_database.php';

class GetData extends GDB {

	protected  $con       = null;

	function GetData(){
	    
	    if(array_key_exists('UserId',$_SESSION)){
	         $this->ActivUser = $this->getUserData($_SESSION["UserId"]);
	    }else{
	        HTTP::redirect ( BASE_URL . '/NotLogin' );
            die();
	    }
	}

 	public function getUserData($user_id){				
		$con = self::startGDB();
		
		$con->Select('Select * From user where id = '.$user_id);
		$user = $con->fetchobject();
		$this->System->design->assign ('UserData',$user[0]);
		
		return $user[0];
	}
	public static function GetUserByName($name){			
		$con = self::startGDB();

		$con->Select('Select id From user where username = "'.$name.'" ');
		$user = $con->fetchobject();
		
		return $user[0]->id;
	}
    public static function GetFriendsForJson($user_id){
		$final = array();
			
		$con = self::startGDB();
		$con->Select('Select user.username as "key", freunde.user_id_2 as value From user, freunde where freunde.user_id_1 = user.id and freunde.user_id_1 = '.$user_id);
		$freunde1 = $con->fetchassoc();
		$con->Select('Select user.username as "key", freunde.user_id_1 as value From user, freunde where freunde.user_id_1 = user.id and freunde.user_id_2 = '.$user_id);
		$freunde2 = $con->fetchassoc();

        $final = array_merge($freunde1,$freunde2);
		
		return json_encode($final);
	}
    public static function GetUserByEmail($email){
		$LoginData = 0;
			
		$con = self::startGDB();
		$con->Select('Select id, username From user where email = "'.$email.'" ');
		$LoginData = $con->fetchobject();

		return $LoginData;
	}
	public static function GetUserById($id){
		$username['username'] = 0;
			
		$con = self::startGDB();
		$con->Select('Select username From user where id = "'.$id.'" ');
		$username = $con->fetcharray();
		return $username['username'];
	}
	public static function GetDesignByUserId($id) {			
		$con = self::startGDB();
		$con->Select('Select design From user where id = "'.$id.'" ');
		$design = $con->fetcharray();
		return $design[0]['design'];
	}
    public static function GetPasswortByUserId($id) {			
		$con = self::startGDB();
		$con->Select('Select passwort From user_page_explorer where id = "'.$id.'" ');
		$passwort = $con->fetcharray();
		return $passwort[0]['passwort'];
	}
}

?>